Start migrating to new CargoResult
authorCarl Lerche <me@carllerche.com>
Thu, 8 May 2014 20:38:16 +0000 (13:38 -0700)
committerCarl Lerche <me@carllerche.com>
Thu, 8 May 2014 20:38:27 +0000 (13:38 -0700)
src/cargo/core/manifest.rs
src/cargo/util/mod.rs
src/cargo/util/result.rs [new file with mode: 0644]

index b43ca5af4c396ea8c6f2b1431d29628f91caec8e..ffb58d79a83cfae2d37371876641284bc860553d 100644 (file)
@@ -1,16 +1,15 @@
-use collections::HashMap;
 use std::fmt;
 use std::fmt::{Show,Formatter};
+use collections::HashMap;
+use serialize::{Encoder,Encodable};
 use core::{
     Dependency,
     NameVer,
     Package,
     Summary
 };
-use core::errors::{CargoResult,CargoError,ToResult,PathError};
-use serialize::{Encoder,Encodable};
+use util::result::CargoResult;
 
-// #[deriving(Decodable,Encodable,Eq,Clone)]
 #[deriving(Eq,Clone)]
 pub struct Manifest {
     summary: Summary,
@@ -179,6 +178,9 @@ pub struct TomlManifest {
 
 impl TomlManifest {
     pub fn to_package(&self, path: &str) -> CargoResult<Package> {
+        // TODO: Convert hte argument to take a Path
+        let path = Path::new(path);
+
         // Get targets
         let targets = normalize(&self.lib, &self.bin);
         // Get deps
@@ -190,15 +192,15 @@ impl TomlManifest {
             }).collect()
         }).unwrap_or_else(|| vec!());
 
-        let root = try!(Path::new(path.to_owned()).dirname_str().map(|s| s.to_owned()).to_result(|_|
-            CargoError::internal(PathError(format!("Couldn't convert {} to a directory name", path)))));
+        // TODO: https://github.com/mozilla/rust/issues/14049
+        let root = Path::new(path.dirname());
 
         Ok(Package::new(
             &Manifest::new(
                 &Summary::new(&self.project.to_name_ver(), deps.as_slice()),
                 targets.as_slice(),
                 &Path::new("target")),
-            &Path::new(root)))
+            &root))
     }
 }
 
index aac3ef5463ab27ded4a886d611ea63c82ea83e47..df596e0e88ae081b1f3e5f858a627ba7e5a48477 100644 (file)
@@ -3,3 +3,4 @@ pub mod graph;
 pub mod process_builder;
 pub mod config;
 pub mod important_paths;
+pub mod result;
diff --git a/src/cargo/util/result.rs b/src/cargo/util/result.rs
new file mode 100644 (file)
index 0000000..7a35d46
--- /dev/null
@@ -0,0 +1,33 @@
+use std::io;
+
+pub type CargoResult<T> = Result<T, CargoError>;
+
+#[deriving(Show)]
+pub struct CargoError {
+    kind: CargoErrorKind,
+    desc: &'static str,
+    detail: Option<~str>
+}
+
+#[deriving(Show)]
+pub enum CargoErrorKind {
+    InternalError,
+    IoError(io::IoError),
+    OtherCargoError
+}
+
+type CargoCliResult<T> = Result<T, CargoCliError>;
+
+#[deriving(Show)]
+pub struct CargoCliError {
+    kind: CargoCliErrorKind,
+    exit_status: uint,
+    desc: &'static str,
+    detail: Option<~str>,
+    cause: Option<CargoError>
+}
+
+#[deriving(Show)]
+pub enum CargoCliErrorKind {
+    OtherCargoCliError
+}